package cn.sc.allinpay.allfavour.business.cashiertransonline;

import android.os.Bundle;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.pai.common.adapter.BaseRecyAdapter;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.DecorationVert;
import cn.sc.allinpay.allfavour.business.common.adapter.CashierTransOnlineAdapter;
import cn.sc.allinpay.allfavour.business.common.data.OilListRecord;


/**
 * activity 交易流水
 * author：pany
 * on 2017/12/1 11:14
 */
public class CashierTransOnlineActivity extends BaseActivity<CashierTransOnlineContract.View, CashierTransOnlineContract.Presenter>
        implements CashierTransOnlineContract.View, AdapterView.OnItemSelectedListener {


    @BindView(R.id.etOrderNo)//订单号
    AppCompatEditText etOrderNo;
    @BindView(R.id.recycler)
    RecyclerView recycler;

    private CashierTransOnlineAdapter transAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_cashier_trans_online;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("快捷加油流水");
    }

    @Override
    protected CashierTransOnlineContract.Presenter bindPresenter() {
        return new CashierTransOnlinePresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        final InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        etOrderNo.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    presenter.reqQueryOilList();
                }
                return false;
            }
        });

        recycler.addItemDecoration(new DecorationVert(this, R.dimen.margin_common, R.dimen.margin_common));
        recycler.setLayoutManager(new LinearLayoutManager(this));// 列表布局
        transAdapter = new CashierTransOnlineAdapter();
        transAdapter.setOnAdapterListener(new BaseRecyAdapter.OnAdapterListener<OilListRecord>() {
            @Override
            public void onItemClick(View view, int position, OilListRecord data) {
                presenter.startTransDetailActivity(data);
            }
        });
        recycler.setAdapter(transAdapter);
    }

    @Override
    public String getOrderNo() {
        return etOrderNo.getText().toString().trim();
    }

    @Override
    public void transAdapterChange(List<OilListRecord> datas) {
        transAdapter.change(datas);
    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        presenter.reqQueryOilList();
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }

    @OnClick({R.id.btnQry})
    public void btnClick(View view) {
        switch (view.getId()){
            case R.id.btnQry:
                presenter.reqQueryOilList();
                break;
        }
    }
}
